package com.yingsheng.bi.hks.basic.enums;

import com.yingsheng.bi.hks.basic.utils.XjyOssUtils;
import io.minio.ObjectWriteResponse;
import lombok.Getter;

import java.io.File;
import java.io.InputStream;
/**
 * 欣佳源对象存储枚举类
 * 通过欣佳源的使用场景创建枚举实例
 * 每个枚举实例对应一个对象存储的使用场景
 * 后续通过增加枚举实例实现灵活支撑场景的扩展
 *
 * @author root
 */
@Getter
public enum XjyOssEnum {

    USER_IMAGE("用户图片", "/public/user/"),

    GOODS_IMAGE("商品图片", "/public/goods/"),

    SERVICE_DETAIL_IMAGE("服务详情图片", "/public/fuwu/"),
    SERVICE_IMAGE("服务图片", "/public/fenlei/"),
    HOME_IMAGE("首页图片", "/public/home/"),
    CONTRACT("合同", "/public/contract/");
    /**
     * 路径下资源的名称或描述
     */
    private final String name;
    /**
     * 资源在桶内路径
     */
    private final String prefixPath;

    XjyOssEnum(String name, String prefixPath) {
        this.name = name;
        this.prefixPath = prefixPath;
    }

    public ObjectWriteResponse putObject(byte[] content, String objectName) {
        return XjyOssUtils.putObject(content, getPrefixPath(), objectName);
    }

    public ObjectWriteResponse putObject(File file, String objectName) {
        return XjyOssUtils.putObject(file, getPrefixPath(), objectName);
    }

    public ObjectWriteResponse putObject(InputStream in, String objectName) {
        return XjyOssUtils.putObject(in, getPrefixPath(), objectName);
    }

    public String getSignedUrl(String objectName) {
        return XjyOssUtils.getSignedUrl(getPrefixPath(), objectName);
    }

    public InputStream getObject(String objectName) {
        return XjyOssUtils.getObject(getPrefixPath(), objectName);
    }

    public boolean deleteObject(String objectName) {
        return XjyOssUtils.deleteObject(getPrefixPath(), objectName);
    }

    public boolean exist(String objectName) {
        return XjyOssUtils.exist(getPrefixPath(), objectName);
    }

}
